fn main() {
	nums := [1, 2, 3, 4, 5]
	
	iter := SquareIterator{
		arr: nums
	}
	
	for squared in iter {
		println(squared)
	}
}

struct SquareIterator {
	arr []int
mut:
	idx int
}

// types that implements a `next` method returning an `Option` can be iterated with a `for` loop
fn (mut iter SquareIterator) next() ?int {
	if iter.idx >= iter.arr.len {
		return error('')
	}
	
	defer {
		iter.idx++
	}
	
	return iter.arr[iter.idx] * iter.arr[iter.idx]
}
